var g = Graphics.createArrayBuffer(20,20,4);
g.dump = _=>{
  var s = "";
  var n = 0;
  for (var y=0;y<g.getHeight();y++) {
    s+="\n";
    for (var x=0;x<g.getWidth();x++) 
      s+="..\"=+:*#"[g.getPixel(x,y)&7];
  }
  return s;
}
g.print = _=>{
  print("`"+g.dump()+"`");
}
var ok = true;
function SHOULD_BE(a) {
  var b = g.dump();
  if (a!=b) {
    console.log("GOT :"+b+"\nSHOULD BE:"+a+"\n================");
    ok = false;
  }
}

// 3 bit 20x20
var img = {
  width:20,height:20,bpp:3,transparent:0,
  palette:new Uint16Array([0,1,2,3,4,5,6,7]),
  buffer: new Uint8Array([0, 0, 2, 73, 36, 0, 0, 0, 0, 9, 36, 146, 73, 0, 0, 0, 36, 146, 73, 36, 146, 64, 0, 18, 73, 36, 146, 73, 36, 128, 1, 36, 146, 73, 36, 146, 72, 0, 146, 73, 36, 146, 73, 100, 144, 9, 36, 146, 73, 36, 191, 201, 4, 146, 73, 36, 146, 95, 244, 146, 73, 36, 146, 73, 47, 250, 73, 36, 146, 89, 36, 151, 253, 36, 146, 73, 45, 250, 75, 254, 146, 73, 36, 146, 95, 245, 255, 73, 36, 146, 73, 36, 191, 255, 164, 146, 73, 32, 146, 73, 127, 210, 73, 36, 144, 9, 36, 146, 201, 36, 146, 73, 0, 18, 73, 36, 146, 73, 36, 128, 1, 36, 146, 73, 36, 146, 72, 0, 2, 73, 36, 146, 73, 36, 0, 0, 0, 146, 73, 36, 144, 0, 0, 0, 0, 36, 146, 64, 0, 0])
};

// Normal
g.clear(1).drawImage(img,0,0); 
SHOULD_BE(`
......."""""".......
....."""""""""".....
...""""""""""""""...
..""""""""""""""""..
..""""""""""""""""..
.""""""""""""""*""".
."""""""""""""##*"".
"""""""""""""###""""
""""""""""""###"""""
"""""*"""""###""""""
""""*##"""###"""""""
"""""###"###""""""""
""""""#####"""""""""
.""""""###""""""""".
."""""""*"""""""""".
..""""""""""""""""..
..""""""""""""""""..
...""""""""""""""...
....."""""""""".....
......."""""".......`);

// Force almost identical draw, but with slow path using _jswrap_drawImageLayerGetPixel
g.clear(1).drawImage(img,0,0,{scale:1.0000001}); 
SHOULD_BE(`
......."""""""......
....."""""""""""....
..."""""""""""""""..
..""""""""""""""""".
..""""""""""""""""".
."""""""""""""""*"""
.""""""""""""""##*""
""""""""""""""###"""
"""""""""""""###""""
"""""*""""""###"""""
""""*##"""####""""""
""""*##"""####""""""
"""""###"####"""""""
""""""######""""""""
.""""""###""""""""""
."""""""*"""""""""""
..""""""""""""""""".
..""""""""""""""""".
..."""""""""""""""..
....."""""""""""....`);

result = ok;
